package com.example.devcaptcha.api;

import cloud.tianai.captcha.validator.common.model.dto.ImageCaptchaTrack;
import com.example.devcaptcha.model.RespModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import tech.zj.anquan.captcha.springboot.starter.application.CaptchaApplication;
import tech.zj.anquan.captcha.springboot.starter.model.CaptchaModel;

/**
 * @Description TODO
 * @Date 2023/1/29 16:41
 * @created by Wanghuafu
 * @Version 1.0.0
 */
@Controller
@RequestMapping("/captcha")
public class CaptchaController
{

    @Autowired
    private CaptchaApplication captchaApplication;


    @GetMapping("/index")
    public String index(){
        return "slider";
    }

    @ResponseBody
    @GetMapping("/get")
    public CaptchaModel getCaptcha(){
        CaptchaModel captchaModel = captchaApplication.generateCaptcha();
        return captchaModel;
    }

    @ResponseBody
    @PostMapping("/check")
    public RespModel checkCaptcha(@RequestParam("id") String id,@RequestBody ImageCaptchaTrack imageCaptchaTrack){
        Boolean checkResult =  captchaApplication.matching(id,imageCaptchaTrack);
        return RespModel.sucInstance(checkResult);
    }

}
